/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package kebut.logic;

public class vinegere extends CryptoBase {
    
    public vinegere(byte[] text, boolean isEncrypt, String key) {
        if (isEncrypt) {
            setPlain(text);
        } else {
            setCipher(text);
        }
        setKey(key);
    }

    @Override
    public void encrypt() {
        byte c;
        int x;
        cipher = new byte[plain.length];
        for (int i = 0; i < plain.length ; i ++){
            c = plain[i];
            if (c < 0)
                x = 256 + (int)c;
            else
                x = (int)c;
            c = ((byte)((((((int)x)+((int)key.charAt(n)))%256))));nextn();
            cipher[i] = c;
        }
        n = 0;
    }

    @Override
    public void decrypt() {
        byte c;
        int x = 0;
        int y = 0;
        plain = new byte[cipher.length];
        for (int i = 0; i < cipher.length ; i ++){
            c = cipher[i];
            
            if (c < 0)
                y = 256 + (int)c;
            else
                y = (int)c;
            
            {x = (((int)y)-((int)key.charAt(n)));nextn();}
            if (x < 0) {
                c = ((byte)(((int)x)+256));
            } else {
                c = ((byte)x);
            }
            plain[i] = c;
        }
        n = 0;
    }
    
}
